use std::collections::HashMap;
use std::sync::{Arc, Mutex, OnceLock, RwLock};
// use once_cell::sync::Lazy;
use tracing::info;
use crate::nosql::client::GioClient;
use crate::nosql::nosql_database::NoSqlDatabase;


pub mod http_request;
pub mod http_response;
pub mod http_router;
pub mod http_server;

// pub static GIO_CLIENT: Lazy<Arc<Mutex<GioClient>>> = Lazy::new(|| {
//     Arc::new(Mutex::new(GioClient::new("localhost:7423".to_string())))
// });
//
// pub fn get_gio_client() -> &'static Arc<Mutex<GioClient>> {
//     &GIO_CLIENT
// }


static GIO_CLIENT: OnceLock<Arc<Mutex<GioClient>>> = OnceLock::new();

pub fn get_global_gio() -> &'static Arc<Mutex<GioClient>> {
    GIO_CLIENT.get().expect("GIOClient 未初始化")
}

pub fn init_global_gio()  {
    let client = Mutex::new(GioClient::new("127.0.0.1:7423".to_string()));
    GIO_CLIENT.set(Arc::new(client)).expect("init_global_gio fail");
    info!("init_global_gio success!");
}

static GIO_NOSQLDATABASE: OnceLock<Arc<RwLock<HashMap<String, String>>>> = OnceLock::new();


pub fn get_gio() -> &'static Arc<RwLock<HashMap<String, String>>> {
    GIO_NOSQLDATABASE.get().expect("GIOClient 未初始化")
}

pub fn init_gio_database()  {
    let nosql = RwLock::new(HashMap::new());
    GIO_NOSQLDATABASE.set(Arc::new(nosql)).expect("init_global_gio fail");
    info!("init_global_gio success!");
}